package com.dqhl.community.view;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.base.BaseMyAdapter;

/**
 * Created by Administrator on 2016/8/2.
 * 选择部门的 popupwindow
 */
public class SectionSelectPopupWindow extends PopupWindow {

    private Activity context;
    private ListView mLvShangHu;
    private String[] str=new String[]{"周边商超1","周边商超2","周边商超3"};

    public SectionSelectPopupWindow(Activity context, AdapterView.OnItemClickListener listener){
        this.context = context;
        View view = LayoutInflater.from(context).inflate(R.layout.popupwindow_section_select, null);

        TextView tvFilterBg = (TextView) view.findViewById(R.id.tv_filter_bg);
        mLvShangHu = (ListView) view.findViewById(R.id.lv_keshi);
        getData(listener);

        tvFilterBg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });

        setBackgroundDrawable(new ColorDrawable(0x70000000));
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        setFocusable(true);
        setOutsideTouchable(true);
        setContentView(view);
        update();
    }

    /**
     * 获取商户类型
     */
    private void getData(final AdapterView.OnItemClickListener listener) {
        mLvShangHu.setAdapter(new BaseMyAdapter(context) {
            @Override
            public int getCount() {
                return str.length;
            }

            @Override
            public String getItem(int i) {
                return str[i];
            }

            @Override
            public long getItemId(int i) {
                return 0;
            }

            @Override
            public View getView(int i, View view, ViewGroup viewGroup) {
                View v=inflater.inflate(R.layout.lv_item_shanghu, viewGroup, false);
                TextView tvShangHu= (TextView) v.findViewById(R.id.tv_keshi_name);
                tvShangHu.setText(str[i]);
                return v;
            }
        });
        mLvShangHu.setOnItemClickListener(listener);
    }


}
